﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using HandyControl.Controls;
using Prism.Mvvm;
using MessageBox = HandyControl.Controls.MessageBox;

namespace YJTTool.Core
{
    public class InheritBase : BindableBase
    {
        /// <summary>
        /// 信息提示
        /// </summary>
        /// <param name="msg"></param>
        public void MessageSuccess(string msg)
        {

            Growl.Success(msg, "提示");
        }
        /// <summary>
        /// 信息提示
        /// </summary>
        /// <param name="msg"></param>
        public void MessageInfo(string msg)
        {

            MessageBox.Info(msg, "提示");
        }
        /// <summary>
        /// 警告提示
        /// </summary>
        /// <param name="msg"></param>
        public void MessageWarning(string msg)
        {
            MessageBox.Warning(msg, "提示");
        }
        /// <summary>
        /// 错误提示
        /// </summary>
        /// <param name="msg"></param>
        public void MessageError(string msg)
        {
            Growl.Error(msg, "提示");
        }

        /// <summary>
        /// 将输入的字符转为大写
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public string ConvertToUpperIfEnglish(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return input;
            }

            bool isEnglish = input.All(c => Char.IsLetter(c) && (Char.IsLower(c) || Char.IsUpper(c)));

            if (isEnglish)
            {
                return input.ToUpper();
            }

            return input;
        }
        public static List<string> CheckFields<T>(T obj)
        {
            List<string> emptyFields = new List<string>();

            var fields = typeof(T).GetFields(BindingFlags.Public | BindingFlags.Instance);

            foreach (var field in fields)
            {
                var value = field.GetValue(obj);

                if (value == null || (value is string str && string.IsNullOrEmpty(str)))
                {
                    emptyFields.Add(field.Name);
                }
            }

            return emptyFields;
        }
    }
    public static class StringExtensions
    {
        /// <summary>
        /// 将字符串转换为整数，如果转换失败返回默认值（0）。
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static int ToIndex(this string columnLetter)
        {
            int columnIndex = 0;

            // 遍历列字母的每一位
            foreach (char c in columnLetter.ToUpper())
            {
                // 将每个字母转换为对应的数字并更新列索引
                columnIndex = columnIndex * 26 + (c - 'A' + 1);
            }

            return columnIndex;
        }

    }
}
